import Vue from 'vue'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
import App from './App.vue'
import VueLazyLoad from 'vue-lazyload'
import { Message } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueCookie from 'vue-cookie'
import store from './store'
// import env from  '../env'

axios.defaults.baseURL='/api';       

// axios.defaults.baseURL='https://www.fastmock.site/mock/8bf6c8d5dc2a88217cfbd95a5f62386e/mock';       
// axios.defaults.baseURL=env.baseURL;       
axios.interceptors.timeout=8000;//超时  
// axios相应拦截器 商城系统和常规的管理后台不同，比较简单所以不用对请求拦截器做过多处理
// 接口错误拦截
axios.interceptors.response.use(function(response){
  let res=response.data;
  let path = location.hash;
  if(res.status == 0){
    return res.data;
  }else if(res.status == 10){
    if (path != '#/index'){
      window.location.href = '/#/login';
    }
    return Promise.reject(res);
  }else{
    // alert(res.msg);
    this.$message.error(res.msg)
    // 抛出异常
    return Promise.reject(res);
  }
},(error)=>{
  let res = error.response;
  // 提示用户已完成支付的订单不要重复支付
  Message.error(res.data.message);
  return Promise.reject(error);
})

Vue.use(VueAxios,axios)//加载
Vue.use(VueCookie)
Vue.use( VueLazyLoad,{
  loading:'/imgs/loading-svg/loading-bars.svg'
})
Vue.prototype.$message=Message
Vue.config.productionTip = false

new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app')
